﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RIS.TMP.WEB.APP.Models;
using RIS.TMP.WEB.APP.AddMigrations;


namespace RIS.TMP.WEB.APP.App_Start
{
    public class main
    {
        /// <summary>
        /// Fac = 1 คือ อ่านแล้วเวลาส่งไปหาAdmin    
        /// Fac = 0 คือ ยังไม่มีการอ่าน
        /// Fac = 3 คือ มีการอัพเดดทแก้ไข
        /// </summary>
        /// <param name="LogedId"></param>
        /// <param name="Fac"></param>
        /// <returns></returns>
        public static int GenAlertMenu(string LogedId, int Fac)
        {
            AllContext db = new AllContext();
            string Id = LogedId;
            Int32 Ids = Convert.ToInt32(db.MRestoreToAdmins.Where(x => x.RecordStatus == "U" && x.Facstatus == Fac).Count());
            return Ids;
        }

        public static string GetNameEm(string CreateBy)
        {
            AllContext db = new AllContext();
            int Id = Convert.ToInt32(CreateBy);
            string FirstName_Th = db.CFEmployees.Where(x => x.EmId == Id).FirstOrDefault().FirstName_Th;
            string SurName_Th = db.CFEmployees.Where(x => x.EmId == Id).FirstOrDefault().SurName_Th;
            return FirstName_Th + " " + SurName_Th;
        }

        public static string GenNameStatusRes(int Id)
        {
            string StatusMR1 = "ซ่อมแซมปรกติ";
            string StatusMR2 = "ซ่อมแซมอุบัติเหตุ";
            string StatusMR3 = "รถเสียนอกพื้นที่";
            string StatusName = null;
            if (Id == 1)
            {
                StatusName = StatusMR1;
            }
            else if (Id == 2)
            {
                StatusName = StatusMR2;
            }
            else if (Id == 3)
            {
                StatusName = StatusMR3;
            }
            else if (Id == 0)
            {
                StatusName = "";
            }

            return StatusName;
        }

        public static string GenNameStatus(int Id)
        {
            string StatusMR1 = "อยู่ระหว่างการรับเรื่องแจ้งซ่อม";
            string StatusMR2 = "ดำเนินการแจ้งซ่อม";
            string StatusMR3 = "รอการปิดแจ้งซ่อม";
            string StatusMR4 = "เสร็จสิ้นการแจ้งซ่อม";
            string StatusName = null;
            if(Id == 1)
            {
                StatusName = StatusMR1;
            }
            else if (Id == 2)
            {
                StatusName = StatusMR2;
            }
            else if (Id == 3)
            {
                StatusName = StatusMR3;
            }
            else if (Id == 4)
            {
                StatusName = StatusMR4;
            }
            else if (Id == 0)
            {
                StatusName = "";
            }

            return StatusName;
        }

        public static string GenCarlicence(int Id)
        {
            AllContext db = new AllContext();

            string Carlicence = db.CAddCars.Where(x => x.AddCarId == Id).FirstOrDefault().AddCarlicence;

            return Carlicence;
        }

    }
}

